< Prev(J) / Next(K) > / View :

Filename: /text/sbasic/shared/03102100.xhp

(section: dimtext) (bookmark: bm_id3149812)
Dim statement
arrays; dimensioning
dimensioning arrays

Dim ステートメント
配列 次元
次元 配列

Dim Statement [Runtime]
Dim ステートメント [実行時](hd_id3149812.1)

Declares a variable or an array.
変数や配列を宣言します。(par_id3143271.2)

(/section: dimtext)

If the variables are separated by commas (for example, DIM sPar1, sPar2, sPar3 AS STRING), only Variant variables can be defined. Use a separate definition line for each variable.
複数の変数名をコンマで区切って 1 度に宣言した場合 (たとえば DIM sPar1, sPar2, sPar3 AS STRING)、変数はすべてバリアント型として定義されます。これを回避するには、変数ごとに分けて定義する必要があります。(par_id3154686.3)

DIM sPar1 AS STRING
DIM sPar1 AS STRING(par_id3156422.4)

DIM sPar2 AS STRING
DIM sPar2 AS STRING(par_id3159252.5)

DIM sPar3 AS STRING
DIM sPar3 AS STRING(par_id3153142.6)

Dim declares local variables within subroutines. Global variables are declared with the PUBLIC or the PRIVATE statement.
Dim ステートメントで宣言される変数は、サブルーチン内部でのみ有効な局所変数です。大域変数を宣言するには、PUBLIC ないし PRIVATE ステートメントを使用する必要があります。(par_id3152576.7)

Syntax:
構文:(hd_id3156443.8)

[ReDim]Dim VarName [(start To end)] [As VarType][, VarName2 [(start To end)] [As VarType][,...]]
[ReDim]Dim VarName [(start To end)] [As VarType][, VarName2 [(start To end)] [As VarType][,...]](par_id3149412.9)

Parameters:
パラメータ:(hd_id3147397.10)

VarName: Any variable or array name.
VarName: 変数ないし配列の名前。(par_id3154730.11)

Start, End: Numerical values or constants that define the number of elements (NumberElements=(end-start)+1) and the index range.
Start, End:要素数 (要素の数 = (end-start)+1) とインデックス範囲を定義する数値または定数。(par_id3147125.12)

Start and End can be numerical expressions if ReDim is applied at the procedure level.
プロシージャーのレベルで ReDim を適用する場合、Start と End には数値表式を使えます。(par_id3153877.13)

VarType: Key word that declares the data type of a variable.
VarType: 変数型を指定するキーワード。(par_id3153510.14)

Keyword: Variable type
キーワード: 変数型(par_id3154015.15)

Bool: Boolean variable (True, False)
Bool: ブール型変数 (True、False)(par_id3153949.16)

Currency: Currency-Variable (Currency with 4 Decimal places)
Currency: 通貨変数 (金額を示す小数点以下 4 桁の数値)(par_id3156275.17)

Date: Date variable
Date: 日付変数(par_id3156057.18)

Double: Double-precision floating-point variable (1,79769313486232 x 10E308 - 4,94065645841247 x 10E-324)
Double: 倍精度型の浮動小数点変数 (1.79769313486232 × 10E308 から 4.94065645841247 × 10E-324)(par_id3148405.19)

Integer: Integer variable (-32768 - 32767)
Integer: 整数変数 (-32768 から 32767)(par_id3148916.20)

Long: Long integer variable (-2.147.483.648 - 2.147.483.647)
Long: ロング整数変数 (-2,147,483,648 から 2,147,483,647)(par_id3150045.21)

Object: Object variable (Note: this variable can only subsequently be defined with Set!)
Object: オブジェクト変数 (注意:この変数を定義する場合は、Set ステートメントを使用する必要があります)(par_id3149255.22)

Single: Single-precision floating-point variable (3,402823 x 10E38 - 1,401298 x 10E-45).
Single: 単精度型の浮動小数点変数 (3.402823 × 10E38 から 1.401298 × 10E-45)。(par_id3155937.23)

String: String variable consisting of a maximum of 64,000 ASCII characters.
String: 最大 64,000 文字からなる文字列変数。(par_id3151251.24)

[Variant]: Variant variable type (contains all types, specified by definition). If a key word is not specified, variables are automatically defined as Variant Type, unless a statement from DefBool to DefVar is used.
[Variant]: バリアント型変数 (定義によりすべてのデータ型を代入できる変数)。キーワードを省略した場合、DefBool や DefVar などのステートメントを使用していない限り、すべての変数は自動的にバリアント型とされます。(par_id3154704.25)

In Office Basic, you do not need to declare variables explicitly. However, you need to declare an array before you can use them. You can declare a variable with the Dim statement, using commas to separate multiple declarations. To declare a variable type, enter a type-declaration character following the name or use a corresponding key word.
Office Basic では、変数を明示的に宣言する必要はありません。 ただし、配列はあらかじめ定義をしておく必要があります。 Dim ステートメントで変数を宣言する場合、コンマで区切ることで複数の宣言を 1 度に行うことができます。 変数のデータ型は、変数名の後に型宣言子またはキーワードを付けることで指定します。(par_id3146316.26)

Office Basic supports single or multi-dimensional arrays that are defined by a specified variable type. Arrays are suitable if the program contains lists or tables that you want to edit. The advantage of arrays is that it is possible to address individual elements according to indexes, which can be formulated as numeric expressions or variables.
Office Basic では 1 次元および多次元配列を使用することができ、変数宣言をする際に変数型を指定します。配列は、プログラム中でリストやテーブルを操作する場合に適しています。配列を使用するメリットとして、インデックスを指定することで配列中の各要素にアクセスできる点がありますが、これらのインデックス指定には数値表式や変数が使えます。(par_id3149924.27)

Arrays are declared with the Dim statement. There are two methods to define the index range:
配列の宣言は、Dim ステートメントで行います。インデックス範囲の指定法には2通りあります。(par_id3148488.28)

DIM text(20) as String REM 21 elements numbered from 0 to 20
DIM text(20) as String REM 0 から 20 までの計 21 個の要素を定義(par_id3154662.29)

DIM text(5 to 25) as String REM 21 elements numbered from 5 to 25
DIM text(5 to 25) as String REM 5 から 25 までの計 21 個の要素を定義(par_id3155604.30)

DIM text(-15 to 5) as String REM 21 elements (including 0)
DIM text(-15 to 5) as String REM (0 も含めた) 計 21 個の要素を定義(par_id3151274.31)

REM numbered from -15 to 5
REM インデックスの範囲は -15 から 5 まで(par_id3152774.32)

Two-dimensional data field
2 次元のデータフィールド(par_id3150829.33)

DIM text(20,2) as String REM 63 elements; form 0 to 20 level 1, from 0 to 20 level 2 and from 0 to 20 level 3.
DIM text(20,2) as String REM 計 63 要素 (それぞれ 0 から 20 までの要素が3レベル分)(par_id3149529.34)

You can declare an array types as dynamic if a ReDim statement defines the number of dimensions in the subroutine or the function that contains the array. Generally, you can only define an array dimension once, and you cannot modify it. Within a subroutine, you can declare an array with ReDim. You can only define dimensions with numeric expressions. This ensures that the fields are only as large as necessary.
配列を使用する関数やサブルーチン内で、ReDim ステートメントにより配列の次元を定義すると、動的な配列を宣言できます。通常、いったん定義をした配列の次元は変更することができません。サブルーチン内では、ReDim ステートメントを使って配列の次元を定義できます。次元の定義には数値表式のみを使用できます。これは、必要最小限のフィールドのみを確保するためです。(par_id3159239.35)

Example:
例:(hd_id3150344.36)

Sub ExampleDim1
Sub ExampleDim1(par_id3150206.37)

Dim sVar As String
Dim sVar As String(par_id3154201.38)

Dim iVar As Integer
Dim iVar As Integer(par_id3146134.39)

sVar = "Office"
sVar = "Star Suite"(par_id3154657.40)

End Sub
End Sub(par_id3148459.41)

Sub ExampleDim2
Sub ExampleDim2(par_id3166424.43)

REM Two-dimensional data field
REM 2 次元データフィールド(par_id3149036.44)

Dim stext(20,2) as String
Dim stext(20,2) as String(par_id3149737.45)

Const sDim as String = " Dimension:"
Const sDim as String = " Dimension:"(par_id3153782.46)

for i = 0 to 20
for i = 0 to 20(par_id3150518.48)

for ii = 0 to 2
for ii = 0 to 2(par_id3166428.49)

stext(i,ii) = str(i) & sDim & str(ii)
stext(i,ii) = str(i) & sDim & str(ii)(par_id3152994.50)

next ii
next ii(par_id3150202.51)

next i
next I(par_id3154370.52)

for i = 0 to 20
for i = 0 to 20(par_id3156166.54)

for ii = 0 to 2
for ii = 0 to 2(par_id3148815.55)

msgbox stext(i,ii)
Msgbox stext(i,ii)(par_id3146981.56)

next ii
next ii(par_id3155125.57)

next i
next I(par_id3154528.58)

End Sub
End Sub(par_id3155087.59)


< Prev / Next >